package com.hefeng.unit.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hefeng.unit.domain.GyDevice;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * 设备信息表;(gy_device)表数据库访问层
 * @author : hzh
 * @date : 2022-11-29
 */
@Mapper
public interface GyDeviceMapper extends BaseMapper<GyDevice>{

  //IPage<GyDevice> selectByPage(@Param(Constants.WRAPPER) Wrapper<GyDevice> wrapper, IPage<GyDevice> page  );

  /**
   * 获取设备状态数量
   * @param userId
   * @return
   */
  List<Map> quantity(@Param("userId") String userId);

  /**
   * 获取主机列表
   * @param userId
   * @return
   */
  @Select("SELECT\n" +
          "\tgy_device.*\n" +
          "FROM\n" +
          "\tgy_device_user\n" +
          "\tINNER JOIN\n" +
          "\tgy_device\n" +
          "\tON \n" +
          "\t\tgy_device_user.device_code = gy_device.device_code\n" +
          "WHERE\n" +
          "\tgy_device_user.is_delete = 1 AND\n" +
          "\tgy_device_user.user_id = #{userId} AND\n" +
          "\tgy_device.is_host = #{isHost} and gy_device.is_deleted = 1")
  List<Map> list(@Param("userId") String userId,@Param("isHost") String isHost);

  @Update(" UPDATE gy_device  SET Is_deleted=2" +
          "WHERE device_id=#{deviceId}  ")
  int device(@Param("deviceId") String deviceId);

}